package org.rds.controller;

import java.util.List;
import java.util.logging.Logger;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.EntityManager;

import org.rds.model.Customer;
import org.rds.model.User;

/**
 * Session Bean implementation class UserEJB
 */

@Stateless
public class UserEJB {

	@Inject
	private Logger log;

	@Inject
	private EntityManager em;

	/**
	 * Default constructor.
	 */
	public UserEJB() {
		// TODO Auto-generated constructor stub
	}

	public List<User> getAllUsers() {
		@SuppressWarnings("unchecked")
		List<User> users = em.createNamedQuery("findAllCustomers").getResultList();
		return users;
	}

	/**
	 * @param user
	 *            the user to save him
	 */
	public void saveUser(User user) {
		log.info("Registering " + user.getLastName());
		em.persist(user);
	}

}
